import { getCurrentTime } from "@/common/common";
import { Card } from "@/components/Card";
import { RouterButton } from "@/components/RouterButton";
import Link from "next/link";


export default function Page(props:any) {

  return (
   <main>
      <h1>Product List Page</h1>
      <h4>{props.dt}</h4>
      <RouterButton />
      <ul style={{maxWidth:'400px'}}>
        {props.data.map((item:any,index:number)=>
         <Card key={index} item={item} />
        )}
      </ul>
   </main>
  )
}


//SSR
export async function getServerSideProps(context:any){
    const {req,res,params,query,...rest} = context;
    console.log({params,query,rest});
    console.log('cookie',req.headers.cookie);
    
    console.log('---------------------->');
    
    const dt = getCurrentTime();
    const response = await fetch('https://dummyjson.com/products');
    const {products:data} = await response.json();


    res.setHeader('Set-Cookie',['name=newking','token=666666']);

    return ({
      props: {
         dt,
         data
      }
    })
}